package com.xzm.project.ui.fragment.tab;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.xzm.project.R;
import com.xzm.project.ui.activity.AppBarLayoutActivity;
import com.xzm.project.ui.activity.CollapsingToolbarLayoutActivity;
import com.xzm.project.ui.activity.DynamicConstraintLayoutActivity;
import com.xzm.project.ui.activity.DynamicFrameLayoutActivity;
import com.xzm.project.ui.activity.DynamicLinearLayoutActivity;
import com.xzm.project.ui.activity.DynamicRelativeLayoutActivity;
import com.xzm.project.ui.activity.MotionEventActivity;
import com.xzm.project.ui.activity.MyCanvasActivity;
import com.xzm.project.ui.activity.MyIntentActivity;
import com.xzm.project.ui.activity.MyViewActivity;
import com.xzm.project.ui.activity.NestActivity;
import com.xzm.project.ui.activity.TestActivity;
import com.xzm.project.ui.activity.ToolbarActivity;
import com.xzm.project.ui.activity.ToolbarHelperActivity;
import com.xzm.project.ui.activity.TweenAnimActivity;
import com.xzm.project.ui.activity.WindowActivity;
import com.xzm.project.ui.adapter.DemoItemAdapter;
import com.xzm.project.ui.bean.DemoItem;

import java.util.ArrayList;
import java.util.List;


public class FragmentOne extends Fragment {
    TextView textView;
    private DemoItemAdapter mAdapter;
//    private List<DemoItem> mlist;
    private RecyclerView recyclerViewDemoItem;

    public static FragmentOne newInstance(String text) {
        FragmentOne fragmentCommon = new FragmentOne();
        Bundle bundle = new Bundle();
        bundle.putString("text", text);
        fragmentCommon.setArguments(bundle);
        return fragmentCommon;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable
            Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_one, container, false);
//        textView= (TextView) view.findViewById(R.id.textView);
//        textView.setText(getArguments().getString("text"));
        initView(view);
        initDates();
        return view;
    }

    private void initView(View view) {
        recyclerViewDemoItem = view.findViewById(R.id.recyclerView_demo_item);
        recyclerViewDemoItem.setLayoutManager(new GridLayoutManager(getContext(), 2));
         textView = view.findViewById(R.id.tv_toolbaer_title);
    }

    public void initDates() {
//        mlist = new ArrayList<>();
        mAdapter = new DemoItemAdapter();
        mAdapter.openLoadAnimation();
        recyclerViewDemoItem.setHasFixedSize(true);
        recyclerViewDemoItem.setAdapter(mAdapter);
        addBaseDate();
    }
    @SuppressLint("SetTextI18n")
    private void addBaseDate() {
        mAdapter.addData(new DemoItem(MyViewActivity.class, "自定义控件"));
        mAdapter.addData(new DemoItem(NestActivity.class, "嵌套事件处理"));
        mAdapter.addData(new DemoItem(MotionEventActivity.class, "事件测试"));
        mAdapter.addData(new DemoItem(TweenAnimActivity.class, "补间动画"));
        mAdapter.addData(new DemoItem(ToolbarActivity.class, "Toolbar工具"));
        mAdapter.addData(new DemoItem(AppBarLayoutActivity.class, "AppBar布局"));
        mAdapter.addData(new DemoItem(CollapsingToolbarLayoutActivity.class, "CollapsingToolbar折叠"));
        mAdapter.addData(new DemoItem(ToolbarHelperActivity.class, "Toolbar工具"));
        mAdapter.addData(new DemoItem(MyIntentActivity.class, "意图Intent"));
        mAdapter.addData(new DemoItem(MyCanvasActivity.class, "画布Canvas"));
        mAdapter.addData(new DemoItem(DynamicLinearLayoutActivity.class, "动态线性布局"));
        mAdapter.addData(new DemoItem(DynamicRelativeLayoutActivity.class, "动态相对布局"));
        mAdapter.addData(new DemoItem(DynamicConstraintLayoutActivity.class, "动态约束布局"));
        mAdapter.addData(new DemoItem(DynamicFrameLayoutActivity.class, "动态帧布局"));
        mAdapter.addData(new DemoItem(TestActivity.class, "TestActivity"));
        mAdapter.addData(new DemoItem(WindowActivity.class, "WindowActivity"));
//        textView.setText(getArguments().getString("text") + String.valueOf(mlist.size()));
    }
}
